#include <iostream>
#include <memory>
#include <functional>

class A
{

  public:
    A()
    {
        id = 1;
        std::cout << "A construst" << id << std::endl;
    };
    A(int i)
    {
        id = i;
        std::cout << "A construst for" << id << std::endl;
    };
    ~A()
    {
        std::cout << "A disconstrust" << id << std::endl;
    }
    A(const A &)
    {
        id = 1;
        std::cout << "A construst const " << id << std::endl;
    };
    A(A &&)
    {
        std::cout << "A disconstrust move" << id << std::endl;
    }

    typedef std::shared_ptr<A> ptr;

  private:
    int id;
};
class B
{
  public:
    B()
    {
        id = 2;
        std::cout << "B construst" << id << std::endl;
    };
    ~B()
    {
        std::cout << "B disconstrust" << id << std::endl;
    }
    typedef std::shared_ptr<B> ptr;

    void func1(A::ptr)
    {
    }
    void func2(std::function<void(A::ptr)>)
    {
    }

  private:
    int id;
};

int main(int argc, char const *argv[])
{
    B b;
    std::cout << "in" << std::endl;
    {
        auto pa = std::make_shared<A>(1);
        b.func2(std::bind(&B::func1, &b, pa));
    }
    std::cout << "out" << std::endl;

    return 0;
}